<template>
  <page-header-wrapper :title="false">
    <a-card title="收款账户设置" style="width: 600px">
      <a-form-model
        ref="accountForm"
        :model="accountForm"
      >
        <a-form-model-item label="收款账户(格式：数字+账户名称，例如：300=天猫国际公户）">
          <a-textarea :rows="10" v-model="accountForm.receive_account"></a-textarea>
        </a-form-model-item>
        <a-button size="small" icon="save" type="primary" :loading="loading" @click="saveAccount">保存收款账户</a-button>
      </a-form-model>
    </a-card>
  </page-header-wrapper>
</template>

<script>
  import { getAccount, postAccount } from '@/api/other'

  export default {
    name: 'AccountSetting',
    data () {
      return {
        loading: false,
        accountForm: {}
      }
    },
    created () {
      this.getAccount()
    },
    methods: {
      getAccount () {
        getAccount().then(res => {
          if (res.status === 0) {
            this.accountForm = res.result.base_setting
          }
        })
      },
      saveAccount () {
        const app = this
        const data = {}
        data['base_setting[receive_account]'] = app.accountForm.receive_account
        app.loading = true
        postAccount(data).then(res => {
          if (res.status === 0) {
            app.getAccount()
          } else {
            app.$warning({
              title: res.msg
            })
          }
        }).finally(() => {
          app.loading = false
        })
      }
    }
  }
</script>

<style scoped>

</style>
